package health.lm.com.mine.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jakewharton.rxbinding2.view.RxView;
import com.lm.sjy.titlebar.widget.CommonTitleBar;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import health.lm.com.component_base.base.mvp.activity.XActivity;
import health.lm.com.component_base.helper.ImageLoaderHelper;
import health.lm.com.mine.R;
import health.lm.com.mine.R2;
import health.lm.com.mine.entity.AllianceBusinessBean;
import health.lm.com.mine.present.AllianceBusinessPresenter;
import health.lm.com.router.ARouterConstant;

/**
 * 联盟商管理后台
 *
 * @author Administrator
 */
@Route(path = ARouterConstant.AllianceBusinessActivity)
public class AllianceBusinessActivity extends XActivity<AllianceBusinessPresenter> {

    @BindView(R2.id.title_bar)
    CommonTitleBar titlebar;
    @BindView(R2.id.tv_money)
    TextView tvMoney;
    @BindView(R2.id.tv_submit)
    TextView tvSubmit;
    @BindView(R2.id.ll_order_list)
    LinearLayout llOrderList;
    @BindView(R2.id.ll_record_list)
    LinearLayout llRecordList;
    @BindView(R2.id.iv_qrcode)
    ImageView iv_qrcode;
    private String money;

    @Override
    public int getLayoutId() {
        return R.layout.activity_alliance_business;
    }

    @Override
    public AllianceBusinessPresenter newP() {
        return new AllianceBusinessPresenter();
    }

    @SuppressLint("CheckResult")
    @Override
    public void initData(Bundle savedInstanceState) {
        //返回按钮
        titlebar.setListener((v, action, extra) -> finish());
        //订单列表
        RxView.clicks(llOrderList)
                .throttleFirst(2, TimeUnit.SECONDS)
                .compose(bindToLife())
                .subscribe(o -> gotoActivity(ARouterConstant.OrderListActivity));
        //提现
        RxView.clicks(tvSubmit)
                .throttleFirst(2, TimeUnit.SECONDS)
                .compose(bindToLife())
                .subscribe(o ->withValueActivity(ARouterConstant.PutForwardActivity).withString("money",money).navigation());
        //提现记录
        RxView.clicks(llRecordList)
                .throttleFirst(2, TimeUnit.SECONDS)
                .compose(bindToLife())
                .subscribe(o ->gotoActivity(ARouterConstant.RecordListActivity));
        getP().getData();
    }


    public void setData(AllianceBusinessBean bean) {
        money = bean.getInfo().getMoney();
        tvMoney.setText(bean.getInfo().getMoney());
        ImageLoaderHelper.getInstance().load(context,bean.getInfo().getPayimg(),iv_qrcode);
    }

    @Override
    protected void onResume() {
        super.onResume();
        getP().getData();
    }
}
